/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.knezevic.realestate.beans;

import com.knezevic.realestate.Identifiable;
import com.knezevic.realestate.RealEstate;
import com.knezevic.realestate.TypeOfRealEstate;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.apache.commons.collections.map.LinkedMap;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 *
 * @author Nemanja
 */
@Entity
public class RealEstateBean implements RealEstate, Identifiable,Serializable{
    
    @Id
    @GeneratedValue
    private Long id;
    @Basic
    private TypeOfRealEstate typeOfRealEstate;
    @Basic
    private String location;
    @Basic
    private double squareMeters;
    @Basic
    private double price;
    @Basic
    private String description;

    @Inject
    public RealEstateBean() {
    }





    public RealEstateBean(TypeOfRealEstate typeOfRealEstate, String location, double squareMeters, double price, String description) {
        this.id = Long.MAX_VALUE-(long)(Math.random()*100000);
        this.typeOfRealEstate = typeOfRealEstate;
        this.location = location;
        this.squareMeters = squareMeters;
        this.price = price;
        this.description = description;
    }

    /**
     * @return the typeOfRealEstate
     */
    @Validate("required")
    public TypeOfRealEstate getTypeOfRealEstate() {
        return typeOfRealEstate;
    }

    /**
     * @param typeOfRealEstate the typeOfRealEstate to set
     */
    public void setTypeOfRealEstate(TypeOfRealEstate typeOfRealEstate) {
        this.typeOfRealEstate = typeOfRealEstate;
    }

    /**
     * @return the location
     */
    @Validate("required,minlength=2,maxlength=25")
    public String getLocation() {
        return location;
    }

    /**
     * @param location the location to set
     */

    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * @return the squareMeters
     */
    @Validate("required,min=8,max=25000000")
    public double getSquareMeters() {
        return squareMeters;
    }

    /**
     * @param squareMeters the squareMeters to set
     */
    public void setSquareMeters(double squareMeters) {
        this.squareMeters = squareMeters;
    }

    /**
     * @return the price
     */
    @Validate("required,min=1,max=25000000")
    public double getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * @return the description
     */
    @Validate("required,minlength=5,maxlength=55")
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return location +" "+typeOfRealEstate;
    }

    @Override
    public boolean equals(Object obj) {
        RealEstateBean r = (RealEstateBean) obj;
        if(this.getID()==r.getID())
            return true;
        return false;
    }

    public long getID() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    
}
